import Vue from "vue"
import Router from "vue-router"
Vue.use(Router)
const Login = () => import("../views/login/login.vue")
const Layout = () => import("../views/layout/index.vue")
const Home = () => import("../views/home/index.vue")
const CageManage = () => import("../views/cage-manage/index.vue")
const Error = () => import("../views/404/error.vue")
const BaseInformation = () => import("../views/base-information/index.vue")
const Adoption = () => import("../views/adoption/index.vue")
const PetManage = () => import("../views/pet-manage/index.vue")
const DataAnalysis = () => import("../views/analyse/data-analyse.vue")
const CageDetail = () => import("../views/cage-manage/cageDetail.vue")
const UserManage = () => import("../views/user-manage/index.vue")
const DogDetail = () => import("../views/cage-manage/dogDetail.vue")
const router = new Router({
  routes: [
    {
      path: "/",
      redirect: "/home",
      component: Layout,
      meta: {
        keepAlive: false
      },
      children: [
        {
          path: "/home",
          name: "home",
          component: Home,
          meta: {
            keepAlive: true
          }
        },
        {
          path: "/cage-manage",
          name: "cage-manage",
          component: CageManage,
          meta: {
            keepAlive: true
          }
        },
        {
          path: "/cage-manage/cage-detail",
          name: "cage-detail",
          component: CageDetail,
          meta: {
            keepAlive: true
          }
        },
        {
          path: "/pet-manage",
          name: "pet-manage",
          component: PetManage,
          meta: {
            keepAlive: false
          }
        },
        {
          path: "/user-manage",
          name: "user-manage",
          component: UserManage,
          meta: {
            keepAlive: false
          }
        },
        {
          path: "/adoption",
          name: "adoption",
          component: Adoption,
          meta: {
            keepAlive: true
          }
        },
        {
          path: "/base-information",
          name: "base-information",
          component: BaseInformation,
          meta: {
            keepAlive: true
          }
        },
        {
          path: "/data-analysis",
          name: "data-analysis",
          component: DataAnalysis,
          meta: {
            keepAlive: true
          }
        },
        {
          path: "/cage-manage/cage-detail/dogDetail",
          name: "dog-detail",
          component: DogDetail,
          meta: {
            keepAlive: true
          }
        }
      ]
    },
    {
      path: "/login",
      name: "login",
      component: Login,
      meta: {
        keepAlive: false
      }
    },
    { path: "*", redirect: "/404" },
    {
      path: "/404",
      name: "Error",
      component: Error,
      meta: {
        keepAlive: false // 是否缓存组件
      }
    }
  ]
})
//页面过长时切换页面保证滚动条在顶部
router.beforeEach((to, from, next) => {
  document.body.scrollTop = 0
  // firefox
  document.documentElement.scrollTop = 0
  next()
})
export default router
